let logger = require('log4js').getLogger("default");
const User = require('../../../models/user/userModel.js')
const { matchedData } = require('express-validator')
const { buildErrObject } = require("../../../utils/buildErrObject");
const checkMobile = async (req, res, next) => {
    req = matchedData(req)
    User.findOne({ mobile: req.mobile, is_delete: false },
        async (err, item) => {
            try {
                if (item === null) {
                    return next()
                }
                return res.status(200).json(buildErrObject(422, "该手机已注册"))
            } catch (error) {
                logger.error(error)
                return res.status(200).json(error)
            }
        })
};

module.exports = { checkMobile }